package com.valveinspectionsys.util;


import java.util.Map;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * 通过SharedPreferences 对一些简单配置数据增、删、改、查
 * @author king
 *
 */
public class SharedPreferenceUtil {
     
     public static final String STTING_INFO="SETTING_INFO";//设置XML的名称
     
     private SharedPreferences setting;
     
      private Context context;
      
      public SharedPreferenceUtil(Context context){
		 this.context=context;
		 setting=context.getSharedPreferences(STTING_INFO, 0);
	 }
	 
	
    
	/**
	 * 查询数据 String数据
	 * @param key
	 * @return
	 */
	public String getValue(String key) {
						
		return setting.getString(key, "");
	}

	/**
	 * 查询boolean 类型数据
	 * @param key
	 * @return
	 */
	public boolean getBoolean(String key){		
		return setting.getBoolean(key, false);
	}

	/**
	 * 获取int 类型数据
	 * @param key
	 * @return
	 */
	public int getInt(String key){
	        return setting.getInt(key, 0);
	}
	
	/**
	 * 添加数据String类型数据
	 * @param key
	 * @param value String
	 * @return
	 */
	public  boolean insertValue(String key,String value){
				
		return setting.edit().putString(key, value).commit();
		
	}
	 
	/**
	 * 添加Boolean 类型数据
	 * @param key
	 * @param b
	 * @return
	 */
	public boolean insertValue(String key,boolean b){
	    
		return setting.edit().putBoolean(key, b).commit();
	}
	
	/**
	 * 添加int 类型数据 
	 * @param key
	 * @param k
	 * @return
	 */
	public boolean  insertValue(String key,int k){
	    
	    return setting.edit().putInt(key, k).commit();
	}
	
	/**
	 * 批量添加字符串类型
	 * @param map
	 * @return
	 */
	public boolean insertValue(Map<String, String> map){

		for(String key:map.keySet()){
			boolean b=setting.edit().putString(key, map.get(key)).commit();
			if(!b){
				return false;
			}
		}
		return true;
		
	}
}
